<template>
	<view class="nav">
		<view class="nav-item" v-for="(item,index) in list" :key="index" 
		:style="item.link.indexOf(value) != -1 ? 'color: #FF6F30 !important' : '' " 
		@click="gotoPath(item.link)"
		v-show="judgePath(item)">
			<image :src="item.icon" mode="widthFix"></image>
			<text class="text">{{item.name}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		name:"diytabbar",
		props:{
			value:{
				type:String,
				default:'index'
			}
		},
		data() {
			return {
				list:[],
				tabList:[]
			};
		},
		mounted() {
			this.$http.sendrequest('/index/Tabbar').then(res=>{
				if(res.code == 1){
					let getdata = uni.getStorageSync('tabbar');
					let dataList = res.data;
					let zpid = uni.getStorageSync('zpid')
					this.$http.sendrequest('/index/Shelfmode').then(res=>{
						if(res.code == 1){
							this.tabList = res.data;
						}
					})
					if(zpid) {
						dataList.forEach(item=>{
							if(item.alias != '发布'){
								this.list.push(item);
							}
						})
					}else{
						if(JSON.stringify(getdata) != JSON.stringify(dataList)){
							this.list = dataList;
							uni.setStorageSync('tabbar',dataList);
						}else this.list = getdata;
					}
				}
			});
		},
		methods:{
			gotoPath(to){
				console.log()
				this.$util.redirectTo(to,{},'switchTab')
			},
			// 判断是否出现
			judgePath(item){
				switch(item.name){
					case '任务大厅':
						if(this.tabList[0] && this.tabList[0].value == 1) return false;
						break;
					case '发布':
						if(this.tabList[1] && this.tabList[1].value == 1) return false;
						break;
				}
				if(item.link.indexOf(this.value) != -1 && !item.nav_index) return false;
				if(item.link.indexOf(this.value) != -1 && item.nav_index) return true;
				if(item.nav_index == 0) return true
				else return false;
			}
		}
	}
</script>

<style lang="scss" scoped>
.nav{
    z-index: 999999;
    position: fixed;
    border-top: 1px solid #f5f5f5;
	background: #FFFFFF;
	width: 100%;
	height: 100rpx;
	bottom: 0;
	left: 0;
	display: flex;
	align-items: center;
	justify-content: space-around;
	padding: 8rpx 0;
	box-sizing: border-box;
	.nav-item{
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: space-around;
		height: 100%;
		color: $uni-tabbar-color;
		image{
			width: 44rpx;
			height: 44rpx;
		}
		.text{
			font-size: 20rpx;
		}
	}
}
</style>